﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace RotovapPlatform.Infrastructure.Common.Data;

public class DesignTimeStorageDbContextFactory : IDesignTimeDbContextFactory<StorageDbContext>
{
	public StorageDbContext CreateDbContext(string[] args)
	{
		var optionsBuilder = new DbContextOptionsBuilder<StorageDbContext>();
		var a = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
		var solutionDir = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\..\\.."));
		var infrastructureDir = Path.Combine(solutionDir, "src", "RotovapPlatform.Infrastructure");
		var folder = Path.Combine(infrastructureDir, "Data");

		if (!Directory.Exists(folder))
			Directory.CreateDirectory(folder);

		var dbPath = Path.Combine(folder, "Rotovap.db");
		optionsBuilder.UseSqlite($"Data Source={dbPath}");

		return new StorageDbContext(optionsBuilder.Options);
	}
}